

*need to download 'rdrobust' command and save it to the same directory as these files

set scheme s1mono
graph set window fontface Times


log using log, replace

*******************************************************************
*Figure 2

local scale 1.5

use data.dta, clear

gen vm_bin = floor(vm/2)*2+1	// 2% bins
collapse num_ref_fut* num_pass_fut* , by(vm_bin)
label var vm_bin "Vote margin of focal referendum"

drop if vm_bin<-15 | vm_bin>35

twoway (scatter num_ref_fut1 vm_bin, mcolor(black)) ///
	(lowess num_ref_fut1 vm_bin if vm_bin<0, lcolor(black)) ///
	(lowess num_ref_fut1 vm_bin if vm_bin>=0, ///
	lcolor(black) xline(0, lcolor(g8) lpattern(shortdash) lwidth(.2)) ///
	graphregion(lstyle(none)) scale(`scale') legend(off) xtitle("") ///
	ytitle("Number of Future Referenda Held") ylabel(, angle(0))), saving(3a, replace)

twoway (scatter num_ref_fut3 vm_bin, mcolor(black)) ///
	(lowess num_ref_fut3 vm_bin if vm_bin<0, lcolor(black)) ///
	(lowess num_ref_fut3 vm_bin if vm_bin>=0, ///
	lcolor(black) xline(0, lcolor(g8) lpattern(shortdash) lwidth(.2)) ///
	graphregion(lstyle(none)) scale(`scale') legend(off) xtitle("") ///
	ylabel(, angle(0))), saving(3b, replace)
	
twoway (scatter num_ref_fut5 vm_bin, mcolor(black)) ///
	(lowess num_ref_fut5 vm_bin if vm_bin<0, lcolor(black)) ///
	(lowess num_ref_fut5 vm_bin if vm_bin>=0, ///
	lcolor(black) xline(0, lcolor(g8) lpattern(shortdash) lwidth(.2)) ///
	graphregion(lstyle(none)) scale(`scale') legend(off) xtitle("") ///
	ylabel(, angle(0))), saving(3c, replace)

twoway (scatter num_pass_fut1 vm_bin, mcolor(black)) ///
	(lowess num_pass_fut1 vm_bin if vm_bin<0, lcolor(black)) ///
	(lowess num_pass_fut1 vm_bin if vm_bin>=0, ///
	lcolor(black) xline(0, lcolor(g8) lpattern(shortdash) lwidth(.2)) ///
	graphregion(lstyle(none)) scale(`scale') legend(off) xtitle("") ///
	ytitle("Number of Future Referenda Passed") ylabel(, angle(0))), saving(3d, replace)

twoway (scatter num_pass_fut3 vm_bin, mcolor(black)) ///
	(lowess num_pass_fut3 vm_bin if vm_bin<0, lcolor(black)) ///
	(lowess num_pass_fut3 vm_bin if vm_bin>=0, ///
	lcolor(black) xline(0, lcolor(g8) lpattern(shortdash) lwidth(.2)) ///
	graphregion(lstyle(none)) scale(`scale') legend(off) xtitle("") ///
	ylabel(, angle(0))), saving(3e, replace)

twoway (scatter num_pass_fut5 vm_bin, mcolor(black)) ///
	(lowess num_pass_fut5 vm_bin if vm_bin<0, lcolor(black)) ///
	(lowess num_pass_fut5 vm_bin if vm_bin>=0, ///
	lcolor(black) xline(0, lcolor(g8) lpattern(shortdash) lwidth(.2)) ///
	graphregion(lstyle(none)) scale(`scale') legend(off) xtitle("") ///
	ylabel(, angle(0))), saving(3f, replace)

graph combine "3a" "3b" "3c" "3d" "3e" "3f" , rows(2) iscale(.5) title("Vote Margin", position(6))



*******************************************************************
*Table 1


global socio_econ_vars total_pop pop_dens2000 perc_under18 perc_over65 perc_hs_ormore perc_coll_ormore ///
	med_house_income perc_recent_house_9000 perc_owner_occupied perc_dem_corrected unemp_rate

* stats for all towns
use data.dta, clear
collapse (mean) $socio_econ_vars (count) ref_id, by(town)
summ $socio_econ_vars
	
* stats for all towns by pass/fail
use data.dta, clear
collapse (mean) $socio_econ_vars (count) ref_id, by(town pass)
summ $socio_econ_vars if pass==0
summ $socio_econ_vars if pass==1
foreach var in $socio_econ_vars {
	display "------------------------------------------------------------------"
	display "`var'"
	ttest `var', by(pass)
}
	
* stats for towns within vm=5
use data.dta, clear
gen vmlt5 = 0
replace vmlt5 = 1 if abs(vm)<5	
keep if vmlt==1
collapse (mean) $socio_econ_vars (count) ref_id, by(town pass)
summ $socio_econ_vars if pass==0
summ $socio_econ_vars if pass==1
foreach var in $socio_econ_vars {
	display "------------------------------------------------------------------"
	display "`var'"
	ttest `var', by(pass)
}



*******************************************************************
*Table 2

use data.dta, clear

global socio_econ_vars total_pop perc_hs_ormore perc_coll_ormore unemp_rate med_house_income inc_sq ///
	perc_recent_house_9000 perc_owner_occupied perc_over65 perc_under18 pop_dens2000 perc_dem_corrected

global ref_chars conserve_funds_at_stake tot_funds_at_stake bond property_tax november


reg num_ref_fut5 i.fail c.vm#i.fail c.vm2#i.fail c.vm3#i.fail $socio_econ_vars i.state_id i.year if d_within5 != 1, vce(cluster town)
reg num_ref_fut5 i.fail c.vm#i.fail c.vm2#i.fail $socio_econ_vars i.state_id i.year if d_within5 != 1, vce(cluster town)
rdrobust num_ref_fut5 vm if d_within5 != 1


reg num_pass_fut5 i.fail c.vm#i.fail c.vm2#i.fail c.vm3#i.fail $socio_econ_vars i.state_id i.year if d_within5 != 1, vce(cluster town)
reg num_pass_fut5 i.fail c.vm#i.fail c.vm2#i.fail $socio_econ_vars i.state_id i.year if d_within5 != 1, vce(cluster town)
rdrobust num_pass_fut5 vm if d_within5 != 1




*******************************************************************
*Table 3


forvalues i = 1/5 {
	reg num_ref_fut`i' i.fail c.vm#i.fail c.vm2#i.fail c.vm3#i.fail $socio_econ_vars i.state_id i.year if d_within`i' != 1, vce(cluster town)
}

forvalues i = 1/5 {
	reg num_pass_fut`i' i.fail c.vm#i.fail c.vm2#i.fail c.vm3#i.fail $socio_econ_vars i.state_id i.year if d_within`i' != 1, vce(cluster town)
}




*******************************************************************
*Table 4

use data.dta, clear

gen lchange_tot_funds5 = log(f1.tot_funds_at_stake) - log(tot_funds_at_stake) if f1.date_stata_form - 5*365 <= date_stata_form

gen change_bonds5 = f1.bond - bond if f1.date_stata_form - 5*365 <= date_stata_form

gen prop_con_tot = conserve_funds_at_stake/tot_funds_at_stake 
gen change_prop_con_tot5 = f1.prop_con_tot - prop_con_tot if f1.date_stata_form - 5*365 <= date_stata_form

gen nov_elec = cond(november==1 & (year==1988 | year==1992 | year==1996 | year==2000 | year==2004 | year==2008 | year==2012), 1, 0)
gen change_novelec5 = f1.nov_elec - nov_elec if f1.date_stata_form - 5*365 <= date_stata_form

gen d_recession = cond(year >= 2007, 1, 0)
gen d_recession_next = cond(f1.year >= 2007, 1, 0)


* next vars
gen nextvm = f1.vm if f1.date_stata_form - 5*365 <= date_stata_form
gen nextdate = f1.date_stata_form
gen changevm = nextvm-vm


* demean and rescale socioecon vars
global socio_econ_vars total_pop perc_hs_ormore perc_coll_ormore unemp_rate med_house_income inc_sq perc_recent_house_9000 perc_owner_occupied perc_over65 perc_under18 pop_dens2000 perc_dem_corrected

foreach var in $socio_econ_vars {
	sum `var'
	local mean = r(mean)
	gen dm_`var' = `var' - `mean'
	replace dm_`var' = dm_`var'/10000 if `var' == total_pop
	replace dm_`var' = dm_`var'/10000 if `var' == med_house_income
	replace dm_`var' = dm_`var'/100000000 if `var' == inc_sq
}

global dm_se_vars dm_total_pop dm_perc_hs_ormore dm_perc_coll_ormore dm_unemp_rate dm_med_house_income dm_inc_sq dm_perc_recent_house_9000 dm_perc_owner_occupied  dm_perc_over65 dm_perc_under18 dm_pop_dens2000 dm_perc_dem_corrected


// Total Funding Proposed - Log

// Full Sample
ttest lchange_tot_funds5, by(pass)
reg lchange_tot_funds5 i.fail $dm_se_vars d_MA_NJ d_recession_next, vce(cluster town)
// Within 10% VM
ttest lchange_tot_funds5 if abs(vm)<=10, by(pass)
reg lchange_tot_funds5 i.fail $dm_se_vars d_MA_NJ d_recession_next if abs(vm)<=10, vce(cluster town)



// Proportion Conservation Funding - Percent Change

// Full Sample
ttest change_prop_con_tot5, by(pass)
reg change_prop_con_tot5 i.fail $dm_se_vars d_MA_NJ d_recession_next, vce(cluster town)
// Within 10% VM
ttest change_prop_con_tot5 if abs(vm)<=10, by(pass)
reg change_prop_con_tot5 i.fail $dm_se_vars d_MA_NJ d_recession_next if abs(vm)<=10, vce(cluster town)



// Bond Financing

// Full Sample
ttest change_bonds5, by(pass)
reg change_bonds5 i.fail $dm_se_vars d_MA_NJ d_recession_next, vce(cluster town)
// Within 10% VM
ttest change_bonds5 if abs(vm)<=10, by(pass)
reg change_bonds5 i.fail $dm_se_vars d_MA_NJ d_recession_next if abs(vm)<=10, vce(cluster town)



// November Election Year Date

// Full Sample
ttest change_novelec5, by(pass)
reg change_novelec5 i.fail $dm_se_vars d_MA_NJ d_recession_next, vce(cluster town)
// Within 10% VM
ttest change_novelec5 if abs(vm)<=10, by(pass)
reg change_novelec5 i.fail $dm_se_vars d_MA_NJ d_recession_next if abs(vm)<=10, vce(cluster town)



*******************************************************************
*Table 5


reg changevm i.fail##c.lchange_tot_funds5 i.fail##c.change_prop_con_tot5 i.fail##c.change_bonds5 i.fail##c.change_novelec5 $dm_se_vars d_MA_NJ d_recession if nextdate - 5*365 <= date_stata_form, vce(cluster town)

reg changevm i.fail##c.lchange_tot_funds5 i.fail##c.change_prop_con_tot5 i.fail##c.change_bonds5 i.fail##c.change_novelec5 $dm_se_vars d_MA_NJ d_recession if abs(vm)<10 & nextdate - 5*365 <= date_stata_form, vce(cluster town)



log close
